package com.dragon.refect.field;

import java.lang.reflect.Field;

/**
 * @author dragon
 * @since 2019/12/2
 */
public class FieldTest1 {

    public static void main(String[] args) throws Exception{
        Class<Dog> dogClass = Dog.class;
        Dog dog = dogClass.newInstance();
        Field sexField = dogClass.getField("sex");
        int sex = sexField.getInt(dog);
        System.out.println("dog sex: " + sex);
        System.out.println("dog sexField name: " + sexField.getName());
        sexField.setInt(dog, 2);
        System.out.println("dog sex: " + dogClass.getField("sex").getInt(dog));
    }
}
